﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ClassLibrary
{
    public class PathUtility
    {
        public static string getLeaf(string path)
        {
            return Path.GetFileName(path);
        }

        public static string getParent(string path)
        {

            string parent = Path.GetDirectoryName(path);
            return parent;
        }

        public static string getParentName(string path)
        {
            return Path.GetFileName(getParent(path));
        }

        public static string getRoot(string path)
        {
            int idx1 = path.IndexOf(Path.DirectorySeparatorChar);
            int idx2 = path.IndexOf(Path.AltDirectorySeparatorChar);
            int idx0 = idx1 > -1 ? idx1 : idx2;

            if (idx0 > -1)
                return path.Substring(0, idx0);
            else return path;
        }
    }
}
